package com.template.tool.StringUtil;

public class StringUtil {

	/**
	 * 将下划线命名转为java命名
	 */
	public  String getClassName(String name) {
		String names[] = name.split("_");
		StringBuffer sbf = new StringBuffer();
		for (int i = 0; i < names.length; i++) {
			String aName = names[i].toLowerCase();
			String firstName = aName.substring(0, 1).toUpperCase();
			String lastString = "";
			if (aName.length() > 1) {
				lastString = aName.substring(1);
			}
			String subName = firstName + lastString;
			sbf.append(subName);

		}
		return sbf.toString();
	}
	
	public boolean isNotNull(String v) {
		return !isNull(v);
	}
	
	public boolean isNull(String v) {
		if(v==null || v.equals("")) {
			return true;
		}else {
			return false;
		}
	}
	
	public String nv(String name, String value) {
		if(isNull(value)) {
			return "";
		}else {
			return name+"="+"\""+value+"\"";
		}
	}
	
	/**
	 * 首字母大写
	 * @param name
	 * @return
	 */
	public  String getFirstUpperName(String aName) {
		
		
			String firstName = aName.substring(0, 1).toUpperCase();
			String lastString = "";
			if (aName.length() > 1) {
				lastString = aName.substring(1);
			}
			String subName = firstName + lastString;
			

		return subName;
	}

	public  String getPropertyName(String name) {
		String names[] = name.split("_");
		String firstName = "";
		String lastString = "";
		StringBuffer sbf = new StringBuffer();
		for (int i = 0; i < names.length; i++) {
			String aName = names[i].toLowerCase();
			firstName = aName.substring(0, 1).toUpperCase();

			if (aName.length() > 1) {
				lastString = aName.substring(1);
			}
			String subName = firstName + lastString;
			sbf.append(subName);

		}

		String pName = sbf.toString();

		firstName = pName.substring(0, 1).toLowerCase();
		lastString = "";
		if (pName.length() > 1) {
			lastString = pName.substring(1);
		}
		String subName = firstName + lastString;

		return subName;
	}
	
	public String getArray(String[] list, int index) {
		String a = null;
	    
		
		return list[index];
	}
	
	 /**
     * 转为整数
     */
    public static String getString(Object obj) {
    	if(obj == null) {
    		return "";
    	}
    	if(obj instanceof String) {
    		return (String) obj;
    	}else{
    		return obj.toString();
    	}
    }
    
	public static void main(String args[]) {
//		System.out.println(StringUtil.getClassName("AD_ORG_ID"));
//		System.out.println(StringUtil.getPropertyName("AD_ORG_ID"));
	}

}
